function debounce(fn, wait, once = true) {
	let timeout = null

	return function() {
		if (once && !timeout) {
			fn()
			timeout = 1
		} else {
			clearTimeout(timeout)
			timeout = setTimeout(fn, wait)
		}
	}
}

function debounce2(fn, wait) {
	let timeout = null

	return function() {
		clearTimeout(timeout)
		timeout = setTimeout(fn, wait)
	}
}

var n = 0
var deb = debounce2(function() {
	console.log("321-" + n)
}, 1000)

var inv = setInterval(function() {
	n++
	deb()
	console.log("123-" + n)
	if (n >= 10) clearInterval(inv)
}, 500)